const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const registerDestination = {};
registerDestination.generateOption = function(seller_id, mws_auth_token, marketplace_id, sqs_url=null){
  let baseOption = {
    'Version': '2013-07-01',
    'Action': 'RegisterDestination',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'MarketplaceId': marketplace_id,
    'Destination.AttributeList.member.1.Key': 'sqsQueueUrl',
    'Destination.AttributeList.member.1.Value': 'https://sqs.us-east-2.amazonaws.com/599885534814/pt-mws-notification',
    'Destination.DeliveryChannel': 'SQS'
  };
  return baseOption;
};

registerDestination._ = function(options) {
  if (!isProduction) {
    return amazonMws.subscriptions.create(options);
  } else {
    console.error("bot not implemented!")
  }
};

registerDestination.registerDestination = function(seller_id, mws_auth_token, marketplace_id, sqs_url) {
  return this._(this.generateOption(seller_id, mws_auth_token, marketplace_id, sqs_url))
};

module.exports = registerDestination;